#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<assert.h>
#include<string.h>
#define NUM 1024
#define OPT_NUM 64
char LineCommand[NUM];
char *myargv[OPT_NUM];
int main()
{
   while(1){
    printf("user@host path#:");
    fflush(stdout); 
   // sleep(10);
    char*s=fgets(LineCommand,sizeof(LineCommand)-1,stdin);   
    assert(s!=NULL); 
   (void)s;
   LineCommand[strlen(LineCommand)-1]=0;
   myargv[0]=strtok(LineCommand," ");
   int i=1;
   while(myargv[i++]=strtok(NULL," "));
  if(myargv[0]!=NULL&&strcmp(myargv[0],"cd")==0)
  {
   if(myargv[1]!=NULL)
   chdir(myargv[1]);
  }
  
#ifdef DEBUG 
  for(int i=0;myargv[i];i++)
   { 
   printf("myargv[%d]:%s\n",i,myargv[i]);
   } 
  #endif
  
  int id=fork();
   assert(id!=-1);
   if(id==0)
   {
   execvp(myargv[0],myargv);
   exit(1);
   }
   waitpid(id,NULL,0);
  }  
   return 0;
  
}

